home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / Xprof / xprof / reply.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  117 lines

  1. /*==================================================================
  2.  *      File :          reply.c
  3.  *      Package:        Xprof
  4.  *
  5.  *      Author :        Aloke Gupta.
  6.  *
  7.  *  (C) Copyright 1992, Aloke Gupta.
  8.  *==================================================================*/
  9.  
  10. /*
  11.  * Processing routines for the replies seen in the message stream.
  12.  * Functions:
  13.  *    1. process_reply(FILE *fp, char *string, GlobalStats *gstats)
  14.  *    2. print_reply_stats(FILE *fp)
  15.  *    3. The routines to process each reply seen. These have the format:
  16.  *           Reply(FILE *fp, reply_index, current_time)
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include "common.h"
  21.  
  22. MsgStats TotalReplyStats;        /* Overall stats for all replies */
  23. MsgStats ReplyStats[MAXREPLIES];    /* Detailed stats for each reply */
  24.  
  25. /*static char in_string[MAXSTRINGSIZE];*/ /* Buffer to read a record into */
  26. static char sbuf[132];            /* Temp. slots for sscanf*/
  27.  
  28. extern MsgType ReplyType[];
  29. extern int lookup_reply();        /* Get index of this request */
  30.  
  31. process_reply(fp, string, gstats)
  32. FILE *fp;                /* Pointer to input stream */
  33. char *string;
  34. GlobalStats *gstats;
  35. {
  36.     char reply_name[80];        /* Name of the current reply */
  37.     int reply_index;            /* Index in the data structures */
  38.     long bytes=0;            /* Number of bytes */
  39.  
  40.     if (TotalReplyStats.invoked == FALSE)
  41.     InitMsgStats(&TotalReplyStats, gstats->current_time, DETAILED, GRAIN1); 
  42.  
  43.     sscanf(string, "%s %s",sbuf, reply_name);
  44.  
  45.     reply_index = lookup_reply(reply_name);
  46.  
  47.     /* Call the action for this reply */
  48.     bytes = ReplyType[reply_index].action(fp,reply_index,gstats->current_time);
  49.  
  50.     /*
  51.      * Fill the data structure for all the replies. The size distribution
  52.      * is maintained for the total number of bytes received.
  53.      */
  54.     FillMsgStats(&TotalReplyStats, gstats->current_time, bytes, bytes); 
  55.  
  56.     gstats->reply_bytes += bytes;
  57.  
  58. }
  59.  
  60. print_reply_stats(fp)
  61. FILE *fp;
  62. {
  63.     int i;
  64.     static char *dashes = {
  65.     "---------------------------------------------------------------"};
  66.  
  67.     if (TotalReplyStats.invoked == FALSE)
  68.         return;
  69.     /*
  70.      * Print the details for all Replies together 
  71.      */
  72.     PrintMsgStats(fp,&TotalReplyStats, "REPLIES ");
  73.  
  74.     /*
  75.      * Brief table for the numbers and byte totals for the replies
  76.      */
  77.     fprintf(fp,"\t%s\n", dashes);
  78.     fprintf(fp,"\n%-25s",  "        REPLY  messages");
  79.     fprintf(fp,"%25s",  "Total Bytes      ");
  80.     fprintf(fp," %19s\n","Number      ");
  81.     fprintf(fp,"\t%s\n", dashes);
  82.     for (i = 0; i < MAXREPLIES; i++)
  83.       if (ReplyStats[i].invoked == TRUE) {
  84.     fprintf(fp,"%-25s", ReplyType[i].name);
  85.     fprintf(fp," %10ld bytes",ReplyStats[i].total_bytes);
  86.     fprintf(fp," (%5.2f%%)", (float) 100 * ReplyStats[i].total_bytes / 
  87.                 TotalReplyStats.total_bytes);
  88.     fprintf(fp," %10ld", ReplyStats[i].number );
  89.     fprintf(fp," (%5.2f%%)", (float) 100 * ReplyStats[i].number / 
  90.                 TotalReplyStats.number);
  91.         fprintf(fp,"\n");
  92.     }
  93.     fprintf(fp,"\t%s\n", dashes);
  94.     fprintf(fp,"%25s"," Grand Total      ");
  95.     fprintf(fp," %10ld bytes         ", TotalReplyStats.total_bytes);
  96.     fprintf(fp," %10ld         \n", TotalReplyStats.number);
  97.     fprintf(fp,"\t%s\n", dashes);
  98.     if (verboselevel > 0) {
  99.     for (i = 0; i < MAXREPLIES; i++)
  100.       if (ReplyStats[i].detailed == DETAILED) 
  101.           PrintMsgStats(fp,&ReplyStats[i], ReplyType[i].name);
  102.     }
  103.     /*
  104.      * Now dump the raw statistics for the messages
  105.      */
  106.     if (verboselevel > 1) {
  107.     if (TotalReplyStats.detailed == DETAILED)
  108.               PrintMsgDetails(fp,&TotalReplyStats, "REPLIES ");
  109.  
  110.     for (i = 0; i < MAXREPLIES; i++)
  111.       if (ReplyStats[i].detailed == DETAILED) 
  112.           PrintMsgDetails(fp,&ReplyStats[i], ReplyType[i].name);
  113.     }
  114.     return;
  115. }
  116.  
  117.